package com.cictec.middleware.gps.engine.position.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cictec.middleware.commons.utils.log.MultiLog;
import com.cictec.middleware.gps.engine.BusInstance;
import com.cictec.middleware.gps.engine.exception.BusPositionHandlerException;
import com.cictec.middleware.gps.engine.position.BusPositionHandler;
import com.cictec.middleware.gps.engine.position.handler.shiftAndTrip.LineTypeExistShitTripHandler;
import com.cictec.middleware.gps.engine.position.handler.shiftAndTrip.LineTypeNotExistShitTripHandler;
import com.cictec.middleware.gps.engine.utils.MultiLogUtil;

/**
 * 班次趟次计算
 * 
 * @author ql
 * @date 2017年9月26日
 */
@Component
public class BusPositionShiftAndTripHandler implements BusPositionHandler {

	private Logger logger = LoggerFactory.getLogger(BusPositionShiftAndTripHandler.class);
	
	@Autowired
	private LineTypeNotExistShitTripHandler lineTypeNotExistShitTripHandler;
	@Autowired
	private LineTypeExistShitTripHandler lineTypeExistShitTripHandler;

	@Override
	public void onHandler(BusInstance busInstance) throws BusPositionHandlerException {

		MultiLog log = MultiLogUtil.getPositionJudgeLog(busInstance);
		
		
//		if(!busInstance.isInDeviate() && busInstance.isInOperateTime() && busInstance.isLineTypeExist()){
		if(busInstance.isInOperateTime()){
			
			if(busInstance.isLineTypeExist()){
				// 有上下行，班次趟次信息处理
				lineTypeExistShitTripHandler.onHandler(busInstance);
			}else{
				// 没有上下行，班次趟次信息处理
				lineTypeNotExistShitTripHandler.onHandler(busInstance);
			}
		}
		
		logger.debug("【班次、趟次】{}", busInstance.getDevCode());
		logger.debug("\t【班次、趟次】当前班次：{}", busInstance.getCurrentShift());
		logger.debug("\t【班次、趟次】当前趟次：{}", busInstance.getCurrentTrip());
		logger.debug("\t【班次、趟次】计划发车时间：{}", busInstance.getCurrentTripPlanTime());
		logger.debug("\t【班次、趟次】实际发车时间：{}", busInstance.getCurrentTripStartTime());
		logger.debug("\t【班次、趟次】下一趟次：{}", busInstance.getNextTrip());
		logger.debug("\t【班次、趟次】下一趟发计划车时间：{}", busInstance.getNextTripPlanTime());
	}
	
	

}